<?php

namespace App\Http\Resources\Index\Chart;

use App\Http\Resources\Resource;

class OnlineResource extends Resource
{

    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        $charts = [
            'timed' => [],
            'data' => [
                'online' => [],
                'gaming' => [],
            ],
        ];

        foreach ($this->resource->toArray() as $item) {
            $charts['timed'][] = date('H:i', $item['timed']);
            $charts['data']['online'][] = $item['online'];
            $charts['data']['gaming'][] = $item['gaming'];
        }

        return $this->getResponse()->setResponseData($charts);
    }
}
